package com.ruoyi.health.api.enums;

import com.fasterxml.jackson.databind.JsonNode;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.health.api.domain.HealthAnalysisResult;
import com.ruoyi.mall.api.domian.RecommendProductsVO;

import java.util.Arrays;
import java.util.function.Function;

public enum ReportEnum {
    GLOSSOSCOPY("1", "舌诊", "SZ", result -> {
        JsonNode results = result.getResults().get("score");
        StringBuilder scoreStringBuilder = new StringBuilder();
        for (int i = 0; i < results.size(); i++) {
            scoreStringBuilder.append(results.get(i));
            if (i < results.size() - 1) {
                scoreStringBuilder.append(",");
            }
        }
        String scoreText = scoreStringBuilder.toString();
        if (StringUtils.isNoneBlank(scoreText)) {
            RecommendProductsVO<String> vo = new RecommendProductsVO<>();
            vo.setParam(scoreText);
            return vo;
        }
        return null;
    }),
    FACE("2", "脉诊", "MZ", result -> {
        return null;
    }),
    SIZHEN("4", "四诊", "SIZ", result -> {return null;});

    final String code;
    final String desc;
    final String tag;
    final Function<HealthAnalysisResult, RecommendProductsVO<?>> getParam;

    ReportEnum(String code, String desc, String tag, Function<HealthAnalysisResult, RecommendProductsVO<?>> getParam) {
        this.code = code;
        this.desc = desc;
        this.tag = tag;
        this.getParam = getParam;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public String getTag() {
        return tag;
    }

    public Function<HealthAnalysisResult, RecommendProductsVO<?>> getGetParam() {
        return getParam;
    }
    public static RecommendProductsVO<?> getQueryParam(String code,HealthAnalysisResult result){
        ReportEnum dataAssemblyEnum = Arrays.stream(ReportEnum.values()).filter(item -> code.equals(item.getCode())).findFirst().orElse(null);
        if(dataAssemblyEnum!=null){
            RecommendProductsVO<?> vo = dataAssemblyEnum.getParam.apply(result);
            vo.setReportType(dataAssemblyEnum);
            return vo;
        }
        return null;
    }
}
